#include "StdAfx.h"
#include "MusicAnalytic.h"

// Processing chunk size
#define BUFF_SIZE           2048

CMusicAnalytic::CMusicAnalytic(void)
{
	m_pZplay = CreateZPlay();
}

CMusicAnalytic::~CMusicAnalytic(void)
{
	m_pZplay->Release();
}

void CMusicAnalytic::Play()
{
	m_pZplay->Play();
}

void CMusicAnalytic::AddFile(const CString& strURL,const CString& strName)
{
	TID3InfoExW id3_info;
	TID3InfoW id3_simple_info;
	MUSIC_INFO info;
	info.strURL = strURL;

	if(m_pZplay->LoadFileID3ExW(strURL, sfAutodetect, &id3_info, 1)) // loading ID3v2
	{
		info.strName = id3_info.Title;
	}
	else
	{
		//ShowErrorMsg();
		info.strName = strName;
		info.strArtist = _T("δ֪");
	}

	m_vecFileInfo.push_back(info);
	int nResult = m_pZplay->AddFileW(strURL,sfAutodetect);
	if(nResult == 0)
	{
		ShowErrorMsg();
		return;
	}

	m_pZplay->Play();
}

void CMusicAnalytic::ShowErrorMsg()
{	
	CString strMsg;
	strMsg = m_pZplay->GetErrorW();
	::AfxMessageBox(strMsg);
}


int CMusicAnalytic::GetMusicPlayIndex()
{
	TStreamStatus status;
	m_pZplay->GetStatus(&status);

	if(status.fPlay == 0)
	{
		return -1;
	}
	else
	{
		return status.nSongIndex;
	}
}

vector<CMusicAnalytic::MUSIC_INFO> CMusicAnalytic::GetMusicInfo()
{
	return m_vecFileInfo;
}